package brad.zimmerman.dungeon.game;

import java.text.DecimalFormat;
import java.util.Random;

public class ClassShop {
	int techlevel, item;
	float discount;
	Random random = new Random(System.nanoTime());
	ClassDrawingHolder draws = new ClassDrawingHolder();
	ClassShop(int techLevel, int item){
		this.techlevel = techLevel;
		this.item = item;
		//11 and 12 are health and mana potions respectively
	}
	public int getItem(){
		return this.item;
	}
	public int getTech(){
		return this.techlevel;
	}
	public void setItem(int value){
		this.item = value;
	}
	public int returnCost(){
		return (int) ((5+techlevel*10));
	}
	public ClassGameStats getEffects(ClassGameStats player){
		switch(item){
			case 1:
				if((this.techlevel + 1)>=1){
					player.blindedImmun = true;
					player.blinded = false;
				}
				if((this.techlevel + 1)>=3){
					player.weaknessImmun = true;
					player.weakness = false;
				}
				if((this.techlevel + 1)>=5){
					player.forgetImmun = true;
					player.forget = false;
				}
				if((this.techlevel + 1)>=7){
					player.manaBurnImmun = true;
					player.manaBurn = false;
				}
				if((this.techlevel + 1)>=9){
					player.poisonedImmun = true;
					player.poisoned = false;
				}
				if((this.techlevel + 1)>=10){
					player.sHUDImmun = true;
					player.sHub = false;
				}
				return player;
			case 2:
				player.player_health += (float)(3 *  (this.techlevel + 1));
				return player;
			case 3:
				player.player_mana += (float)(3 *  (this.techlevel + 1));
				return player;
			case 4:
				player.dodgeRate += (float)(1.5 *  (this.techlevel + 1))/100;
				return player;
			case 5:
				if (player.renewalRate > 0){
					player.renewalRate += (int)((this.techlevel + 3)) / 2;
				}
				return player;
			case 6:
				player.moreMagic += (float)(5 *  (this.techlevel + 1))/100;
				return player;
			case 7:
				player.permModifier += (float)(5 *  (this.techlevel + 1))/100;
				return player;
			case 8:
				player.twiceHit += (float)(1.5 *  (this.techlevel + 1))/100;
				return player;
			case 9:
				player.cautiousLuck += (float)(10 *  (this.techlevel + 1))/100;
				return player;
			case 10:
				if((this.techlevel + 1)>=1){
					player.playerSight = 2;
				}
				if((this.techlevel + 1)>=5){
					player.playerSight = 3;
				}
				if((this.techlevel + 1)==10){
					player.playerSight = 4;
				}
				return player;
			case 11:player.player_hpotions++;return player;
			case 12:
				if(!player.hitIncreaseAttack){
					player.player_mpotions ++;
				}else{
					player.player_hpotions ++;
				}
			
				return player;
			case 13:player.extraLife = true;return player;
			case 14:
				player.manaBurn = false;
				player.poisoned = false;
				player.blinded = false;
				player.forget = false;
				player.weakness = false;
				player.sHub = false;
				return player;
			case 15:player.player_currenthealth = player.player_health;
			player.player_currentmana = player.player_mana; return player;
			case 16:
				if(player.worshipGod){
					player.player_piety += 10;
				}
				return player;
			case 17: player.goldBonus *= 1.25; return player;
			case 18: player.trashGlyph(); return player;
			case 19: return randomizeStats(player);
			case 20: return randomizeStatsWitch(player);
			case 21: 
				ClassAltar altar = new ClassAltar(10,10,random.nextInt( draws.godImages.length ));
				return altar.godsBlessing(player, true);
			case 22:return rearrageGlyphs(player);
			case 23:
				int pick = random.nextInt( draws.classImages.length );
				while(pick == 44 || pick == 36 || pick == 29 || pick == 26 || pick == 21 || pick == 8){
					pick = random.nextInt( draws.classImages.length );
				}
				player.classSkills(pick);
				return player;
			case 24:
				if(player.player_level>12){
					player.unlockedCharacters = true;
				}
				return player;
			default:return player;
		}
	}
	
	public String otherShopNames(){
		switch(item){
			case 11:return "Health Potion";
			case 12:return "Mana Potion";
			case 13:return "Extra Life";
			case 14:return "Cure All";
			case 15:return "Revitalize Serum";
			case 16:return "Temple Offering";
			case 17:return "Rock Tumbler";
			case 18:return "Glyph Sale!";
			case 19:return "Fortune Teller";
			case 20:return "Witch's Curse";
			case 21:return "Templar's Curse";
			case 22:return "Mage's Firesale";
			case 23:return "Princess's Might";
			case 24:return "Summon Through The Veil";
			default:return "";
		}
	}
	
	public ClassGameStats randomizeStats(ClassGameStats player){
		Random random = new Random(System.currentTimeMillis());
		int total = player.player_health + player.player_mana + player.player_attack + 10;
		player.player_health = 0 ;
		player.player_mana = 0;
		player.player_attack = 0;
		for(int i = 0; i < total; i++){
			switch(random.nextInt( 3 )){
				case 0:player.player_health++;break;
				case 1:player.player_mana++;break;
				case 2:player.player_attack++;break;
				default:player.player_health++;break;
			}
		}
		if(player.player_currenthealth > player.player_health){
			player.player_currenthealth = player.player_health;
		}
		if(player.player_currentmana > player.player_mana){
			player.player_currentmana = player.player_mana;
		}
		return player;
	}
	
	public ClassGameStats randomizeStatsWitch(ClassGameStats player){
		Random random = new Random(System.currentTimeMillis());
		int avoid,pick;
		int total = player.player_health + player.player_mana + player.player_attack + 15;
		player.player_health = 1;
		player.player_mana = 1;
		player.player_attack = 1;
		avoid = random.nextInt( 3 );
		for(int i = 0; i < total; i++){
			pick = random.nextInt( 3 );
			while (pick == avoid){
				pick = random.nextInt( 3 );
			}
			switch(pick){
				case 0:player.player_health++;break;
				case 1:player.player_mana++;break;
				case 2:player.player_attack++;break;
				default:player.player_health++;break;
			}
		}
		if(player.player_currenthealth > player.player_health){
			player.player_currenthealth = player.player_health;
		}
		if(player.player_currentmana > player.player_mana){
			player.player_currentmana = player.player_mana;
		}
		return player;
	}
	
	public String printEffectsShops(ClassGameStats player){
		String holder = "";
		DecimalFormat dec = new DecimalFormat("###.##");
		switch(item){
			case 1:
				if((this.techlevel + 1)>=1){
					holder = "Player immune to blind when purchased";
				}
				if((this.techlevel + 1)>=3){
					holder = "Player immune to blind and weakness when purchased";
				}
				if((this.techlevel + 1)>=5){
					holder = "Player immune to amnesia, weakness, and blind when purchased";
				}
				if((this.techlevel + 1)>=7){
					holder = "Player immune to amnesia, weakness, blind, and manaBurn when purchased";
				}
				if((this.techlevel + 1)>=9){
					holder = "Player immune to poison, amnesia, weakness, blind, and manaBurn when purchased";
				}
				if((this.techlevel + 1)>=10){
					holder = "Player immune to all status ailments when purchased";
				}
				break;
			case 2:
				//holder = "Adds " + (2.5 *  (this.techlevel + 1)) + "% physical resistance when purchased";
				holder = "Player Health: " + dec.format(player.player_health) + "->"+dec.format((player.player_health + (float)(3 *  (this.techlevel + 1)))) +"";
				break;
			case 3:
				//holder = "Adds " + (2.5 *  (this.techlevel + 1)) + "% magical resistance when purchased";
				holder = "Player Mana: " + dec.format(player.player_mana) + "->"+dec.format((player.player_mana + (float)(3 *  (this.techlevel + 1))))+"";
				break;
			case 4:
				//holder = "Adds " + (2.5 *  (this.techlevel + 1)) + "% evasion when purchased";
				holder = "Dodge Rate: " + dec.format(player.dodgeRate* 100) + "%->"+ dec.format((player.dodgeRate + (float)(1.5 *  (this.techlevel + 1))/100)* 100)+"%";
				break;
			case 5:
				//holder = "Increases shroud regeneration by " + (int)((this.techlevel + 3)) / 2 + " when purchased";
				if (player.renewalRate > 0){
					holder = "Shroud Regen Rate: " + dec.format(player.renewalRate) + "->"+dec.format((player.renewalRate + (int)((this.techlevel + 3)) / 2));
				}else{
					holder += "Shroud Regen Rate: 0->0";
				}
				break;
			case 6:
				//holder = "Increases magic attack by " + (5 *  (this.techlevel + 1)) + "% when purchased";
				holder = "Magic Attack Bonus: " + dec.format(player.moreMagic* 100) + "%->"+dec.format((player.moreMagic + (float)(5 *  (this.techlevel + 1))/100)* 100)+"%";
				break;
			case 7:
				//holder = "Increases physical attack by " + (5 *  (this.techlevel + 1)) + "% when purchased";
				holder = "Physical Attack Bonus: " + dec.format(player.permModifier* 100) + "%->"+dec.format((player.permModifier + (float)(5 *  (this.techlevel + 1))/100)* 100)+"%";
				break;
			case 8:
				//holder = "Increases chance of hitting twice by " + (2.5 *  (this.techlevel + 1)) + "% when purchased";
				holder = "Double Hit Chance: " + dec.format(player.twiceHit* 100) + "%->"+dec.format((player.twiceHit + (float)(1.5 *  (this.techlevel + 1))/100)* 100)+"%";
				break;
			case 9:
				//holder = "Increases range of attack by " + (10 *  (this.techlevel + 1))+ "% when purchased";
				if (player.gamblersLuck > 0 && player.cautiousLuck == 0){
					holder = "Attack Range: " + dec.format(((float) (player.returnAttack() * .7))) + "-" + dec.format(((float)(player.returnAttack() * (1+player.gamblersLuck))));
					holder += "     With Upgrade: " + dec.format(((float) (player.returnAttack() * .7))) + "-" + dec.format(((float)(player.returnAttack() * (1+player.gamblersLuck+((float)(10 *  (this.techlevel + 1))/100)))));
				}
				else if (player.gamblersLuck == 0 && player.cautiousLuck == 0){
					
					holder = "Attack Range: " + dec.format(((float) (player.returnAttack()))) + "-" + dec.format(((float)(player.returnAttack() * (1))));
					holder += "     With Upgrade: " + dec.format(((float) (player.returnAttack()))) + "-" + dec.format(((float)(player.returnAttack() * (1+((float)(10 *  (this.techlevel + 1))/100)))));

				}
				else if (player.gamblersLuck == 0 && player.cautiousLuck > 0){
					holder = "Attack Range: " + dec.format(((float) (player.returnAttack()))) + "-" + dec.format(((float)(player.returnAttack() * (1 +player.cautiousLuck))));
					holder += "     With Upgrade: " + dec.format(((float) (player.returnAttack()))) + "-" + dec.format(((float)(player.returnAttack() * (1+player.cautiousLuck+((float)(10 *  (this.techlevel + 1))/100)))));
				}
				else if (player.gamblersLuck > 0 && player.cautiousLuck > 0){
					holder = "Attack Range: " + dec.format(((float) (player.returnAttack() * .7))) + "-" + dec.format(((float)(player.returnAttack() * (1+player.cautiousLuck+player.gamblersLuck))));
					holder += "     With Upgrade: " + dec.format(((float) (player.returnAttack() * .7))) + "-" + dec.format(((float)(player.returnAttack() * (1+player.cautiousLuck+player.gamblersLuck+((float)(10 *  (this.techlevel + 1))/100)))));
				}
				break;
			case 10:
				if((this.techlevel + 1)>=1){
					holder = "Increases sight to " + 2 + " squares when purchased";
				}
				if((this.techlevel + 1)>=5){
					holder = "Increases sight to " + 3 + " squares when purchased";
				}
				if((this.techlevel + 1)==10){
					holder = "Increases sight to " + 4 + " squares when purchased";
				}
				break;
			case 11: 
				holder = "Adds 1 health potion to inventory";
				break;
			case 12: 
				if(!player.hitIncreaseAttack){
					holder = "Adds 1 mana potion to inventory";
				}else{
					holder = "Adds 1 health potion to inventory";
				}
				break;
			case 13: 
				holder = "Gives the player an extra life";
				break;
			case 14: 
				holder = "Instantly Cures All Ailments";
				break;
			case 15: 
				holder = "Instantly restores health and mana completely";
				break;
			case 16: 
				holder = "Offer gold to current god for +10 piety. No piety gained for athiests";
				break;
			case 17: 
				holder = "Increases discovered gold value by 25%";
				break;
			case 18:
				holder = "Adds +1 to your racial glyph bonus. Same as trashing a glyph";
				break;
			case 19:
				holder = "Randomizes player's stats, making them slightly higher on average";
				break;
			case 20:
				holder = "Reduces one of your stats to 1. Supercharges the other two stats";
				break;
			case 21:
				holder = "Bestows the blessings and curses of a random god upon the player";
				break;
			case 22:
				holder = "Converts every owned glyph into a random other glyph";
				break;
			case 23:
				holder = "Bestows a random otherwordly power upon the princess";
				break;
			case 24:
				holder = "Has a chance to summon travellers permanently from beyond the veil";
				break;
			default:break;
		}
		System.out.println();
		return holder;
	}
	
	public String printEffectsBuyScreen(){
		String holder = "";
		ClassDrawingHolder Draws = new ClassDrawingHolder();
		switch(item){
			case 1:
				if((this.techlevel + 1)>=1){
					holder = "Player immune to blind when purchased";
				}
				if((this.techlevel + 1)>=4){
					holder = "Player immune to blind and weakness when purchased";
				}
				if((this.techlevel + 1)>=6){
					holder = "Player immune to amnesia, weakness, and blind when purchased";
				}
				if((this.techlevel + 1)>=8){
					holder = "Player immune to amnesia, weakness, blind, and manaBurn when purchased";
				}
				if((this.techlevel + 1)>=10){
					holder = "Player immune to all status ailments when purchased";
				}
				break;
			case 2:
				holder = "Adds " + (3 *  (this.techlevel + 1)) + " to max health when purchased";
				break;
			case 3:
				holder = "Adds " + (3 *  (this.techlevel + 1)) + " to max mana when purchased";
				break;
			case 4:
				holder = "Adds " + (1.5 *  (this.techlevel + 1)) + "% evasion when purchased";
				break;
			case 5:
				holder = "Increases shroud regeneration by " + (int)((this.techlevel + 3)) / 2 + " when purchased";
				break;
			case 6:
				holder = "Increases magic attack by " + (5 *  (this.techlevel + 1)) + "% when purchased";
				break;
			case 7:
				holder = "Increases physical attack by " + (5 *  (this.techlevel + 1)) + "% when purchased";
				break;
			case 8:
				holder = "Increases chance of hitting twice by " + (1.5 *  (this.techlevel + 1)) + "% when purchased";
				break;
			case 9:
				holder = "Increases range of attack by " + (10 *  (this.techlevel + 1))+ "% when purchased";
				break;
			case 10:
				if((this.techlevel + 1)>=1){
					holder = "Increases sight by " + 2 + " when purchased";
				}
				if((this.techlevel + 1)>=5){
					holder = "Increases sight by " + 3 + " when purchased";
				}
				if((this.techlevel + 1)==10){
					holder = "Increases sight by " + 4 + " when purchased";
				}
				break;
			case 11: 
				holder = "Increases number of gold piles by " + this.techlevel + " for each dungeon permanently";
				break;
			case 12: 
				holder = "Increases gold value by " + (this.techlevel * 2) + " for each gold pile found permanently";
				break;
			case 13: 
				holder = "Potion healing rate increased to " + (40 + (2.5 *  (this.techlevel))) + "% permanently";
				break;
			case 14: 
				holder = "Increases shop discount to " + (5 *  (this.techlevel)) + "% permanently";
				break;
			case 15: 
				holder = "Increases shop frequency by " + ((this.techlevel)+1)/2 + " permanently\n";
				holder += "Increases altar frequency by " + ((this.techlevel)+1)/3 + " permanently";
				break;
			case 16: 
				holder = "Allows worship in the following gods: \n";
				for (int i = 0; i < this.techlevel + 5; i++){
					holder += Draws.godNames[i];
					if (i != this.techlevel +4){
						holder += ", ";
					}
				}
				break;
			case 17: 
				holder = "Increases starting HP/MP by " + (this.techlevel) + " permanently";
				break;
			case 18: 
				holder = "Increases ritual effectiveness by " + (5 *  (this.techlevel)) + "% permanently";
				break;
			case 19:
				holder = "Randomizes player's stats, making them slightly higher on average";
				break;
			case 20:
				holder = "Reduces one of your stats to 1. Supercharges the other two stats";
				break;
			case 21:
				holder = "Bestows the blessings and curses of a random god upon the player";
				break;
			case 22:
				holder = "Converts every owned glyph into a random other glyph";
				break;
			case 23:
				holder = "Bestows a random otherwordly power upon the princess";
				break;
			case 24:
				holder = "Has a chance to summon travellers permanently from beyond the veil";
				break;
			default:break;
		}
		return holder;
	}
	
	public ClassGameStats rearrageGlyphs(ClassGameStats player){
		int pick;
		for(int i =0 ; i < player.currentGlyphs.length;i++){
			if (player.currentGlyphs[i] != 0){
				Random random = new Random(System.currentTimeMillis());
				pick = random.nextInt( draws.glyphImages.length );
				while(pick == 3 || inArray(draws.glyphImages,pick)){
					pick = random.nextInt( draws.glyphImages.length );
				}
				player.currentGlyphs[i] = pick;
			}
		}
		return player;
	}
	
	public boolean inArray(int[] array, int pick){
		for(int number:array){
			if (pick == number){
				return true;
			}
		}
		return false;
	}
	
	public int[] returnUpgradeCost(int level){
		int gold = 25 * ((level + 1) * (level + 1));
		int ruins = 5 * ((level + 1) * (level + 1));
		int essence = 5 * ((level + 1) * (level + 1));
		int[] value = {gold,ruins,essence};
		return value;
	}
	
}
